﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace RpgEditor
{
    public class role
    {
        const int MAXLEVEL = 30;
        public SByte[,] data = new SByte[MAXLEVEL, 6];
        mainForm form = null;
        private String fn;
        public role(mainForm f)
        {
            form = f;
        }
        public void setFn(String fn)
        {
            this.fn = fn;
            form.textBox23.Text = fn;
        }

        public String getFn()
        {
            return fn;
        }

        public void init()
        {
            for (int i = 0; i < MAXLEVEL; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    data[i, j] = 0;
                }
            }
        }

        public void save()
        {
            FileStream fs1 = new FileStream(fn, FileMode.Create, FileAccess.Write);
            BinaryWriter dis = new BinaryWriter(fs1, System.Text.Encoding.Default);
            MyIO.writeByte(dis, MAXLEVEL);
            for (int i = 0; i < MAXLEVEL; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    MyIO.writeByte(dis, data[i, j]);
                }
            }
            dis.Close();

        }

        public void getRoleInfo(String fn)
        {

            FileStream fs1 = new FileStream(fn, FileMode.Open, FileAccess.Read);
            BinaryReader dis = new BinaryReader(fs1, System.Text.Encoding.Default);
            int num = MyIO.readByte(dis);
            for (int i = 0; i < num; i++)
            {                
                for (int j = 0; j < 6; j++)
                {
                    data[i,j] = MyIO.readByte(dis);
                }
            }
            dis.Close();

        }

        public void display()
        {
            
            form.listBox9.Items.Clear();
            for (int i = 0; i < MAXLEVEL; i++)
            {
                form.listBox9.Items.Add(i);
            }
            form.listBox9.SelectedIndex = 0;

            displayatt(0);
        }

        public void displayatt(int i)
        {
            if (i >= MAXLEVEL)
            {
                return;
            }

            form.comboBox4.SelectedIndex = data[0, 0];
            form.textBox29.Text = "" + data[0, 5];
            form.textBox25.Text = "" + data[i, 1];
            form.textBox26.Text = "" + data[i, 2];
            form.textBox27.Text = "" + data[i, 3];
            form.textBox28.Text = "" + data[i, 4];
        }

        public void up(int i1)
        {
            if (i1 >= MAXLEVEL)
            {
                return;
            }

            data[i1,0] = (SByte)form.comboBox4.SelectedIndex;
            data[i1, 1] = SByte.Parse(form.textBox25.Text);
            data[i1, 2] = SByte.Parse(form.textBox26.Text);
            data[i1, 3] = SByte.Parse(form.textBox27.Text);
            data[i1, 4] = SByte.Parse(form.textBox28.Text);
            data[i1, 5] = SByte.Parse(form.textBox29.Text);
        }
    }
}
